function cleanArray (actual) {
  const newArray = []
  for (let i = 0; i < actual.length; i++) {
    if (actual[i]) {
      newArray.push(actual[i])
    }
  }
  return newArray
}

function param (json) {
  if (!json) return ''
  return cleanArray(
    Object.keys(json).map(key => {
      // if (json[key] === undefined) return ''
      return key + '=' + json[key]
    })
  ).join('&')
}

function getQueryObject (url) {
  url = url == null ? window.location.href : url
  const search = url.substring(url.lastIndexOf('?') + 1)
  const obj = {}
  const reg = /([^?&=]+)=([^?&=]*)/g
  search.replace(reg, (rs, $1, $2) => {
    const name = decodeURIComponent($1)
    let val = decodeURIComponent($2)
    val = String(val)
    obj[name] = val
    return rs
  })
  return obj
}

module.exports = {
  cleanArray,
  param,
  getQueryObject
}



